/**
 * 创建store
 */

import { createStore, applyMiddleware } from 'redux'
import reducer from './reducer'
import thunk from 'redux-thunk'
//  初始化购物车默认数据
const initState = {
  num1: 100,
  num2: 20,
  num3: 30
}

// 自定义中间件=>日志监控
const logger = store => next => action => {
  console.log('开始执行', action)
  // 调用 middleware 链中下一个 middleware 的 dispatch
  let result = next(action)
  console.log('执行结束', store.getState())
  // 一般会是 action 本身，除非
  // 后面的 middleware 修改了它
  return result
}
const store = createStore(reducer, initState, applyMiddleware(thunk, logger))

export default store